package com.jianyun.jyzs.widget;

import android.os.Parcel;
import android.os.Parcelable;

import com.jianyun.jyzs.utils.LoginCache;

import java.util.ArrayList;


public class SelectConfig implements Parcelable {

    private ArrayList<String> initialSelectList;//初始化的时候已选择的；
    private ArrayList<String> unCheckableList; //不能点击的item
    private int maxSelectedNumber = Integer.MAX_VALUE;

    private boolean selfCheck = false;//默认不能选自己

    public SelectConfig() {
        unCheckableList = new ArrayList<>();
        unCheckableList.add(LoginCache.getInstance().getUserInfo().getUserId());
        initialSelectList = new ArrayList<>();
        initialSelectList.add(LoginCache.getInstance().getUserInfo().getUserId());
    }

    protected SelectConfig(Parcel in) {
        initialSelectList = in.createStringArrayList();
        unCheckableList = in.createStringArrayList();
        maxSelectedNumber = in.readInt();
        selfCheck = in.readByte() != 0;
    }

    public static final Creator<SelectConfig> CREATOR = new Creator<SelectConfig>() {
        @Override
        public SelectConfig createFromParcel(Parcel in) {
            return new SelectConfig(in);
        }

        @Override
        public SelectConfig[] newArray(int size) {
            return new SelectConfig[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeStringList(initialSelectList);
        dest.writeStringList(unCheckableList);
        dest.writeInt(maxSelectedNumber);
        dest.writeByte((byte) (selfCheck ? 1 : 0));
    }

    public ArrayList<String> getInitialSelectList() {
        return initialSelectList;
    }

    public void setInitialSelectList(ArrayList<String> initialSelectList) {
        for (String id : initialSelectList) {
            if (!this.initialSelectList.contains(id)) {
                this.initialSelectList.add(id);
            }
        }
    }

    public ArrayList<String> getUnCheckableList() {
        return unCheckableList;
    }

    public void setUnCheckableList(ArrayList<String> unCheckableList) {
        for (String id : unCheckableList) {
            if (!this.unCheckableList.contains(id)) {
                this.unCheckableList.add(id);
            }
            if (!initialSelectList.contains(id)) {
                initialSelectList.add(id);
            }
        }
    }

    public int getMaxSelectedNumber() {
        return maxSelectedNumber;
    }

    public boolean isSelfCheck() {
        return selfCheck;
    }

    public void setSelfCheck(boolean selfCheck) {
        this.selfCheck = selfCheck;
    }

    public void setMaxSelectedNumber(int maxSelectedNumber) {
        this.maxSelectedNumber = maxSelectedNumber;
    }
}
